package ecom.beans.dao;

import ecom.beans.PurchaseBean;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

public class PurchaseDAO extends DAO {

    public static void savePurchase(PurchaseBean purchase) {
        saveOrUpdate(purchase);
    }

    public static void deletePurchase(PurchaseBean purchase) {
        delete(purchase);
    }

    public static void updatePurchase(PurchaseBean purchase) {
        saveOrUpdate(purchase);
    }

    public static Set getAllPurchases(String order) {
        return fetchAll("PurchaseBean.findAll", null, order);
    }

    public static PurchaseBean getById(String iban, Integer idProductstore, String idProduct, Date dateAchat) {
        List parameters = new ArrayList();
        parameters.add("iban");
        parameters.add(iban);
        parameters.add("idProductstore");
        parameters.add(idProductstore);
        parameters.add("idProduct");
        parameters.add(idProduct);
        parameters.add("dateAchat");
        parameters.add(dateAchat);
        return (PurchaseBean) fetchOne("PurchaseBean.findByPK", parameters);
    }

    public static Set getLastSales(String order) {
        return fetchAllLimit("PurchaseBean.lastSales", null, order, 11);
    }
}
